package com.java1412.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 网关配置类
 *
 * @author java1412
 * @create 2022-09-05 15:01
 */
@Configuration
public class GatewayConfig {
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        // 进行路由配置
        routes.route("path_route_1",
                // 请求的地址中含有guonei直接跳转到百度国内新闻
                r -> r.path("/guonei").uri("http://news.baidu.com/guonei"));
        routes.route("path_route_2",
                r -> r.path("/guoji").uri("http://news.baidu.com/guoji"));
        return routes.build();
    }
}
